package com.study.testSpringBoot.cors;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
@ConditionalOnClass(CorsFilter.class)
//@ConditionalOnProperty(name = {"web.cors"},havingValue = "true")
public class CorsFilterConfigruation {

//    @ConditionalOnMissingBean(value = CorsFilter.class)
//    @Bean
//    public FilterRegistrationBean corsFilter(){
//        System.out.println("加载跨域访问配置");
//        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
//        CorsFilter requestContxtFilter = new CorsFilter();
//        registrationBean.setFilter(requestContxtFilter);
//        List<String> urlPatterns = new ArrayList<>();
//        urlPatterns.add("/*");
//        registrationBean.setUrlPatterns(urlPatterns);
//        registrationBean.setAsyncSupported(true);
//        registrationBean.setOrder(0);
//        return registrationBean;
//    }
}
